<template>
  <SysDialog draggable :title="dialog.title" :visible="dialog.visible" :width="dialog.width" :height="dialog.height"
    @onClose="onClose" @onConfirm="confirm">
    <template v-slot:content>
      <!-- 内容组件 -->
      <el-form :model="dialogModel" ref="addAuditForm" :rules="rules" label-width="120px" size="default">
        <el-form-item prop="versions" label="文件版本">
          <el-input v-model="dialogModel.versions" clearable></el-input>
        </el-form-item>
        <!-- <el-form-item prop="taskBaselineId" label="基线选择">
          <el-select v-model="dialogModel.taskBaselineId" clearable style="width: 100%" placeholder="请选择...">
            <el-option v-for="(item, index) in dictDateBaseline.dictItemVO" :key="item.id" :label="item.name"
              :value="item.id" />
          </el-select>
        </el-form-item> -->
        <el-form-item prop="taskBaselineId" label="当前基线">
          <!-- <el-input v-model="currentbase" disabled></el-input> -->
          <div class="input">
            {{ currentbase }}
          </div>
        </el-form-item>
        <el-form-item prop="auditorStageId" label="阶段选择">
          <el-select v-model="dialogModel.auditorStageId" @change="handleChange" clearable style="width: 100%"
            placeholder="请选择...">
            <el-option v-for="(item) in stageIds" :key="item.auditorStageId" :label="item.name"
              :value="item.auditorStageId" />
          </el-select>
        </el-form-item>
        <el-form-item prop="wordFiles" label="文件上传">
          <!-- <el-input v-model="dialogModel.versions" clearable></el-input> -->
          <fileUpMore @fileUp="fileUp" ref="RefFileUp1"></fileUpMore>
        </el-form-item>
      </el-form>
    </template>
  </SysDialog>
</template>

<script setup lang='ts'>
import { ref, onMounted } from "vue";
import { ElForm } from "element-plus";
import SysDialog from "@/components/SysDialog.vue";
import useDialog from "@/hooks/useDialog";
import useInstance from "@/hooks/useInstance";
import { EditType, Title } from "@/type/BaseEnum";
import AuditAddEditTs from "@/composables/02Review/01ProjectMan/AuditAddEdit";
import { log } from "console";
const addAuditForm = ref<InstanceType<typeof ElForm>>();
const RefFileUp1 = ref();
const { dialogModel, rules } = AuditAddEditTs();
const emit = defineEmits(["saveFile"]);
// 使用
const { dialog, onClose, onShow } = useDialog();
const { global, proxy } = useInstance();
// 父级数据
const fileUp = (file) => {
  if (file.length > 0) {
    dialogModel.wordFiles = file;
  } else {
    dialogModel.wordFiles = "";
  }
};
const handleChange = (item) => {
  console.log(item);
};
const props = defineProps({
  // dictDateBaseline: {
  //   type: Object,
  //   default: () => { }
  // },
  stageIds: {
    type: Array<any>,
    default: () => [],
  },
  taskId: {
    type: String,
    default: "",
  },
  currentbase: {
    type: String,
    default: '',
  },
});
// 保存
const confirm = () => {
  // console.log(taskId);
  // if (!dialogModel.wordFile) {
  //   global.$message({ message: '请上传文件', type: 'warning' })
  // }
  addAuditForm.value?.validate((isOk) => {
    if (isOk) {
      emit("saveFile", dialogModel);
      onClose();
      RefFileUp1.value?.clearFile();
    }
  });
};
const show = (type: string, row?: any, taskBaselineId?) => {
  console.log("show", taskBaselineId);
  dialog.width = 650;
  dialog.height = 350;
  dialog.title = EditType.ADD ? Title.ADD : Title.EDIT;
  onShow();
  global.$resetForm(addAuditForm.value, dialogModel);

  dialogModel.taskId = props.taskId;
  if (type === EditType.ADD) {
    dialogModel.taskBaselineId = row;
  }
  if (type === EditType.EDIT) {
    console.log(row);

    dialog.title = Title.EDIT
    dialogModel.versions = row.versions
    dialogModel.taskId = props.taskId;
    dialogModel.taskBaselineId = taskBaselineId;
    dialogModel.auditorStageId = row.auditorStageId
    dialogModel.filesId = row.id
  }
};
defineExpose({
  show,
});
</script>
<style scoped lang='scss'>
.input {
  border: 1px solid #dcdfe6;
  padding-left: 10px;
  border-radius: 5px;
  width: 100%;
}
</style>